/**
 * 绘制折线
 * @param {Earth} options.earth 折线的渲染容器
 * @param {Array} options.positions 折线轮廓数据 [ lng, lat, lng, lat... ]
 * @param {Array} options.color 折线填充颜色 colorArray
 * @param {Array} options.width 折线宽度
 * @param {Array} options.loop 折线是否为环线 首尾相连
 * @param {Boolean} options.changeStatus 是否可编辑属性
 * @param {object} options.data 临时数据存放
 * 
 * @methods update(options) 更新折线数据
 * 
 * @returns {Polygon} Polygon实例
 */

function DrawPolyline (options) {

    let radian = Math.PI / 180;
    let positions = options.positions.map((item) => {
        return [
            item[0] * radian,
            item[1] * radian,
            item[2] || 1,
        ]
    })
    let polyline = new XE.Obj.Polyline(options.earth);

    polyline.xbsjFromJSON({
        customProp: options.data,
        ground: options.ground === undefined ? true : options.ground,
        loop: options.loop || false,
        positions: positions || [],
        show: options.show === undefined ? true : options.show,
        width: options.width || 2
    })
    polyline.material.XbsjColorMaterial.color = options.color || [ 1,1,1,1 ]

    // return polyline
    polyline._node = this
    this.XEObj = polyline
    this.data = options.data || null
    this.changeStatus = options.changeStatus === undefined ? true : options.changeStatus
}


DrawPolyline.prototype.destroy = function () {
    this.XEObj._node = null
    this.XEObj.destroy()
}

DrawPolyline.prototype.update = function (options) {
    if (!this.changeStatus) {
        return
    }
    for (let k in options) {
        if (k == 'color') {
            this.XEObj.material.XbsjColorMaterial.color = options.color
        } else {
            this.XEObj[k] = options[k]
        }
    }
}

DrawPolyline.prototype.setShow = function (options) {
    this.XEObj.show = options
}


export default DrawPolyline